package com.itheima.d3_stream;

import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/*
        目标：掌握Stream流的创建。

        1 单列集合获取Stream流
        2 双列集合获取Stream流
        3 数组获取Stream流
        4 同一种类型多个数据获取Stream流
 */
public class StreamTest2 {
    //stream使用步骤
    //获取元素的stream对象
    //调用方法对数据进行运算处理
    //获取处理结果，遍历打印
    public static void main(String[] args) {
        // 1、如何获取List集合的Stream流？
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰","张无忌","周芷若","赵敏","张强");
        //获取单列集合stream对象,调用对象的stream方法
        Stream<String> stream = names.stream();
        stream.forEach((s)->{
            System.out.println(s);
        });
        //获取双列集合的stream对象，需要先获取单列集合的stream
        HashMap<String, String> shuang = new HashMap<>();
       shuang.put("阿米娅","雷姆必拓");
       shuang.put("来一","雷姆必拓");
       shuang.put("提风","吹风机");
       //获取键值对的stream
        Set<Map.Entry<String, String>> e = shuang.entrySet();
        e.stream().forEach((s)->{
            System.out.println(s);
        });

        //获取键的Steam
        Set<String> strings = shuang.keySet();
        strings.stream().forEach((s)->{
            System.out.println(s);
        });
        //获取数组stream流
        int[] shuzu = {1,2,3,4,5,6,7};
        //使用Arrays调用stream方法传入数组
        IntStream stream1 = Arrays.stream(shuzu);
        stream1.forEach((s)->{
            System.out.println(s);
        });
        //获取同个对象多个数据的stream对象
        Stream<String> s1 = Stream.of("孙悟空", "牛魔王", "蜘蛛精");
        s1.forEach((s)->{
            System.out.println(s);
        });


    }
}
